$(function (){
	try {
		CheckApiBox();
		LoadApiRate();
	}catch (e) {}

	WindowHeight(0);setTimeout("WindowHeight(-1)",500);

});


// 检测表单
function CheckForm(){
	if ($id('theme').value == ""){ alert("上级渠道商名称不能为空！");$id('theme').focus();return false; }
	if ($id('isApi1').checked){
		if ($id('apiID').value == 2){	// 景安网络
			if ($id('apiUsername2').value==""){ alert("Access Id(身份标识)不能为空！");$id('apiUsername2').focus();return false; }
			if ($id('apiUserPwd2').value==""){ alert("Access Key(密钥)不能为空！");$id('apiUserPwd2').focus();return false; }
		}else if ($id('apiID').value == 5){
			if ($id('apiUsername5').value==""){ alert("Api ID不能为空！");$id('apiUsername5').focus();return false; }
			if ($id('apiUserPwd5').value==""){ alert("密钥不能为空！");$id('apiUserPwd5').focus();return false; }
		}else{
			if ($id('apiID').value==""){ alert("请选择API接口！");$id('apiID').focus();return false; }
			if ($id('apiDomain').value==""){ alert("上级API域名不能为空！");$id('apiDomain').focus();return false; }
			if ($id('apiManageUrl').value==""){ alert("上级云服务器面板域名不能为空！");$id('apiManageUrl').focus();return false; }
			if ($id('apiUsername').value==""){ alert("上级代理名不能为空！");$id('apiUsername').focus();return false; }
			if ($id('apiUserPwd').value==""){ alert("上级代理密码不能为空！");$id('apiUserPwd').focus();return false; }
		}
	}
	return true
}


// 检测API接口
function CheckApiBox(){
	if ($id('isApi1').checked){
		$id("apiBox").style.display="";
	}else{
		$id("apiBox").style.display="none";
	}
	WindowHeight(0);
}


// 读取API接口的费率信息
function LoadApiRate(){
	if ($id('apiID').value == 1 || $id('apiID').value >= 6){
		$('.api16Class').css('display','');
		if ($id('apiID').value == 1){
			AjaxGetDeal('vpsCompany_deal.php?mudi=loadApiRate&apiID='+ $id('apiID').value);
			$('.api1Class').css('display','');
		}
	}else{
		$('.api16Class').css('display','none');
		$('.api1Class').css('display','none');
	}
	if ($id('apiID').value == 2){
		$('.api2Class').css('display','');
	}else{
		$('.api2Class').css('display','none');
	}
	if ($id('apiID').value == 5){
		$('.api5Class').css('display','');
	}else{
		$('.api5Class').css('display','none');
	}
	WindowHeight(0);
}


// 设置空白栏费率
function SetRate(){
	if (ToFloat($id('rateDay').value) == 0){ $id('rateDay').value = $id('rateDayApi').value; }
	if (ToFloat($id('rateWeek').value) == 0){ $id('rateWeek').value = $id('rateWeekApi').value; }
	if (ToFloat($id('rateMonth').value) == 0){ $id('rateMonth').value = $id('rateMonthApi').value; }
	if (ToFloat($id('rate3Month').value) == 0){ $id('rate3Month').value = $id('rate3MonthApi').value; }
	if (ToFloat($id('rate6Month').value) == 0){ $id('rate6Month').value = $id('rate6MonthApi').value; }
	if (ToFloat($id('rateYear').value) == 0){ $id('rateYear').value = $id('rateYearApi').value; }
	if (ToFloat($id('rate2Year').value) == 0){ $id('rate2Year').value = $id('rate2YearApi').value; }
	if (ToFloat($id('rate3Year').value) == 0){ $id('rate3Year').value = $id('rate3YearApi').value; }
	if (ToFloat($id('rate4Year').value) == 0){ $id('rate4Year').value = $id('rate4YearApi').value; }
	if (ToFloat($id('rate5Year').value) == 0){ $id('rate5Year').value = $id('rate5YearApi').value; }

	var rateDayNew='',rateWeekNew='',rateMonthNew='',rate3MonthNew='',rate6MonthNew='',rateYearNew='',rate2YearNew='',rate3YearNew='',rate4YearNew='',rate5YearNew='';
	if (ToFloat($id('rateDay').value) != ToFloat($id('rateDayApi').value)){
		rateDayNew = '参考费率：'+ $id('rateDayApi').value;
	}
	if (ToFloat($id('rateWeek').value) != ToFloat($id('rateWeekApi').value)){
		rateWeekNew = '参考费率：'+ $id('rateWeekApi').value;
	}
	if (ToFloat($id('rateMonth').value) != ToFloat($id('rateMonthApi').value)){
		rateMonthNew = '参考费率：'+ $id('rateMonthApi').value;
	}
	if (ToFloat($id('rate3Month').value) != ToFloat($id('rate3MonthApi').value)){
		rate3MonthNew = '参考费率：'+ $id('rate3MonthApi').value;
	}
	if (ToFloat($id('rate6Month').value) != ToFloat($id('rate6MonthApi').value)){
		rate6MonthNew = '参考费率：'+ $id('rate6MonthApi').value;
	}
	if (ToFloat($id('rateYear').value) != ToFloat($id('rateYearApi').value)){
		rateYearNew = '参考费率：'+ $id('rateYearApi').value;
	}
	if (ToFloat($id('rate2Year').value) != ToFloat($id('rate2YearApi').value)){
		rate2YearNew = '参考费率：'+ $id('rate2YearApi').value;
	}
	if (ToFloat($id('rate3Year').value) != ToFloat($id('rate3YearApi').value)){
		rate3YearNew = '参考费率：'+ $id('rate3YearApi').value;
	}
	if (ToFloat($id('rate4Year').value) != ToFloat($id('rate4YearApi').value)){
		rate4YearNew = '参考费率：'+ $id('rate4YearApi').value;
	}
	if (ToFloat($id('rate5Year').value) != ToFloat($id('rate5YearApi').value)){
		rate5YearNew = '参考费率：'+ $id('rate5YearApi').value;
	}
	$id('rateDayApiStr').innerHTML = rateDayNew;
	$id('rateWeekApiStr').innerHTML = rateWeekNew;
	$id('rateMonthApiStr').innerHTML = rateMonthNew;
	$id('rate3MonthApiStr').innerHTML = rate3MonthNew;
	$id('rate6MonthApiStr').innerHTML = rate6MonthNew;
	$id('rateYearApiStr').innerHTML = rateYearNew;
	$id('rate2YearApiStr').innerHTML = rate2YearNew;
	$id('rate3YearApiStr').innerHTML = rate3YearNew;
	$id('rate4YearApiStr').innerHTML = rate4YearNew;
	$id('rate5YearApiStr').innerHTML = rate5YearNew;
}


// 恢复默认费率
function LoadDefRate(){
	if ($id('apiID').value==""){ alert("请先选择API接口！");$id('apiID').focus();return false; }
	$id('rateDay').value = $id('rateDayApi').value;
	$id('rateWeek').value = $id('rateWeekApi').value;
	$id('rateMonth').value = $id('rateMonthApi').value;
	$id('rate3Month').value = $id('rate3MonthApi').value;
	$id('rate6Month').value = $id('rate6MonthApi').value;
	$id('rateYear').value = $id('rateYearApi').value;
	$id('rate2Year').value = $id('rate2YearApi').value;
	$id('rate3Year').value = $id('rate3YearApi').value;
	$id('rate4Year').value = $id('rate4YearApi').value;
	$id('rate5Year').value = $id('rate5YearApi').value;
	SetRate();
}